package com.changjiang.luban.service.basic;

import com.changjiang.luban.dao.basic.ActivityBannerDao;
import com.changjiang.luban.dao.domain.basic.ActivityBanner;
import com.changjiang.luban.utils.ContrastUtils;
import com.changjiang.luban.utils.data.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ActivityBannerDao
 * Description:
 *
 * @author tengchenglong
 * @version v0.1
 * @date 2018/7/25 - 10:37
 */
@SuppressWarnings("ALL")
@Service
public class ActivityBannerServiceImpl implements ActivityBannerServiceI{
    @Autowired
    private ActivityBannerDao bannerDao;

    @Override
    public boolean saveBanner(ActivityBanner banner) {
        return bannerDao.saveEntity(banner);
    }

    @Override
    public boolean updateBanner(ActivityBanner banner) {
        return bannerDao.update(banner);
    }

    @Override
    public boolean updateState(Long id, Integer state) {
        ActivityBanner banner = findById(id);
        banner.setState(state);
        return updateBanner(banner);
    }

    @Override
    public boolean delete(Long id) {
        return bannerDao.deleteEntity(findById(id));
    }

    @Override
    public ActivityBanner findById(Long id) {
        return bannerDao.findById(id).get();
    }

    @Override
    public Page<ActivityBanner> pageByTitle(String parameter, Page page) {
        String sql = "select * from a_banner b  where 1=1";
        if (ContrastUtils.isNull(parameter)) {
            sql += " and b.title like '%" + parameter + "%'";
        }
        sql += "  order by create_time desc";
        return bannerDao.page(sql, page, ActivityBanner.class);
    }

    @Override
    public List<ActivityBanner> bannerList() {
        String sql = "select * from a_banner b where b.type = 2 and  b.state = 1";
        return bannerDao.list(sql,ActivityBanner.class);
    }


}
